#include <thread>
#include "../include/TaskInfo.h"

TaskInfo::TaskInfo(std::function<void()> t, TaskPriority p, std::string id, std::string desc)
    :task(std::move(t))
    ,priority(p)
    ,submitTime(std::chrono::steady_clock::now())
    ,taskId(std::move(id))
    ,description(std::move(desc))
{
    std::this_thread::sleep_for(std::chrono::nanoseconds(1));
}

bool TaskInfo::operator<(const TaskInfo& other) const
{
    if(this->priority != other.priority)
    {
        return this->priority < other.priority;
    }

    return this->submitTime > other.submitTime;
}


std::string taskStatusToString(TaskStatus status)
{
    switch(status)
    {
    case TaskStatus::WAITING: 
        return "等待中";
    case TaskStatus::RUNNING:
        return "正在执行";        
    case TaskStatus::COMPLETED: 
        return "已完成";
    case TaskStatus::FAILED: 
        return "失败";
    case TaskStatus::CANCELED: 
        return "已取消";
    }

    return "未知状态";
}


std::string priorityToString(TaskPriority priority)
{
    switch(priority)
    {
    case TaskPriority::LOW:
        return "低";
    case TaskPriority::MEDIUM:
        return "中";
    case TaskPriority::HIGH:
        return "高";
    case TaskPriority::CRITICAL:
        return "关键";
    }

    return "未知";
}